package com.ycc.biz.common;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Objects;

@Data
public abstract class BaseEntity<T extends BaseEntity<T>> extends Model<T> {
    @TableId(type = IdType.ASSIGN_ID)
    private String id;

    @TableField(fill = FieldFill.INSERT, value = "create_time")
    private LocalDateTime createTime;

    @TableField(fill = FieldFill.INSERT, value = "created_by")  
    private String createdBy;  

    @TableField(fill = FieldFill.INSERT_UPDATE, value = "update_time")  
    private LocalDateTime updateTime;  

    @TableField(fill = FieldFill.INSERT_UPDATE, value = "updated_by")  
    private String updatedBy;  

    @TableLogic(value = "0", delval = "1")
    private Integer delFlag;

    @TableField(value = "remark")
    private String remark;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BaseEntity that = (BaseEntity) o;
        return Objects.equals(id, that.id); // 仅通过主键 id 判断相等性
    }

    @Override
    public int hashCode() {
        return Objects.hash(id); // 仅基于主键生成哈希值
    }
}  
